import Base from 'models/base';

import SystemUtil from 'utils/systemUtil';

export default class CouponTaoData extends Base {
  constructor(coupon) {
    super();

    this.itemId = coupon.itemid;
    this.activityId = coupon.activityid;
    this.title = coupon.itemshorttitle;
    this.pic = `${coupon.itempic}_200x200.jpg`;
    this.desc = coupon.couponexplain;

    this.money = this.getNumberData(coupon, 'couponmoney');
    this.total = this.getNumberData(coupon, 'couponnum');
    this.count = this.getNumberData(coupon, 'couponsurplus');
    this.price = this.getNumberData(coupon, 'itemprice');
    this.couponPrice = this.getNumberData(coupon, 'itemendprice');
  }

  getNumberData(coupon, field) {
    let value = coupon[field];
    if (SystemUtil.isEmpty(value)) {
      return '';
    }

    value = Number(value);
    return value;
  }
}
